﻿/*
 * File: DynamicMessageStore.cs
 * Author: Gourav Das
 * Purpose: Implements a Dynamic database of Strings.
 * Created: May 03 2011
 */

using System;
using System.Collections.Generic;
using System.Threading;

namespace _22yards.Core
{
    public class Message
    {
        /// <summary>
        /// Category of Message
        /// </summary>
        public string Category = string.Empty;
    
        /// <summary>
        /// String Message
        /// </summary>
        public string Msg = string.Empty;

        /// <summary>
        /// Initializes a new instance of the <see cref="Message"/> class.
        /// </summary>
        public Message ()
        {
            Category = string.Empty;
            Msg = string.Empty;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Message"/> class.
        /// </summary>
        /// <param name="_cat">The _cat.</param>
        /// <param name="_msg">The _MSG.</param>
        public Message (string _cat, string _msg)
        {
            Category = _cat;
            Msg = _msg;
        }
    }
    public class DynamicMessageStore
    {
        private List<Message> messages = new List<Message>();

        /// <summary>
        /// Gets the messages list.
        /// </summary>
        public List<Message> Messages
        {
            get
            {
                return messages;
            }

            set
            {
                messages = value;
            }

        }

        /// <summary>
        /// Gets the size of the messages list
        /// </summary>
        public int Size
        {
            get
            {
                return messages.Count;
            }

        }

        /// <summary>
        /// Gets the random message from the messages list.
        /// </summary>
        /// <returns>String</returns>
        public string GetRandomMessage()
        {
            return (Size <= 0)? string.Empty: Messages[new Random().Next() % Size].Msg;
        }
    }
}
